<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>总结生命周期</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<div id="root">
    <h2 :style="{opacity}">欢迎学习Vue</h2>
    <button @click="opacity=1">透明度为1</button>
    <button @click="stop">点我停止变换</button>
</div>
</body>
<script type="text/javascript">
    Vue.config.productionTip=false
    const vm=new Vue({
        el:'#root',
        data:{
            opacity:1
        },
        methods:{
            stop(){
               this.$destroy()
                // clearInterval(this.timer)//停的温柔
            }
        },
        //挂载（）
        mounted(){
            console.log('mounted',this)
                this.timer=setInterval(()=>{
                    this.opacity-=0.01
                    if (this.opacity<= 0) this.opacity=1
                },16)
        },

        beforeDestroy() {
            console.log('vm即将消失')
            clearInterval(this.timer)
        },
    })
</script>
</html>